using System.Linq;
using System.Security.Cryptography;
using CthulhuDomain.GameEntities;
using System;

namespace CthulhuDomain.Strategies
{
  public class ZigStrategy : MovementStrategy
  {
    public ZigStrategy(DomainEntity subject) : base(subject) { }


    public override void Move(IRectangle context, Services.IGameTime time)
    {
      Subject.Position = new Vector2Adapter(Subject.Position.X + Subject.Speed, Subject.Position.Y);
      InvertMovement(context);
      var randomNext = StaticRandomNumberGenerator.RandomNext(1, 2000);
      if (randomNext > 1 && randomNext < 3)
        Subject.AddShoot();

      randomNext = StaticRandomNumberGenerator.RandomNext(1, 3000);
      if (randomNext > 1 && randomNext < 3)
        Subject.AddPowerUp();
    }

    private void InvertMovement(IRectangle context)
    {
      if (!(Subject.Position.X >= context.Width - Subject.Width) && !(Subject.Position.X <= 0)) return;
      Subject.Position = new Vector2Adapter(Subject.Position.X, Subject.Position.Y + Subject.Height / 2); 
      Subject.Speed *= -1;
    }
  }
}